package com.example.myapplication.ui.dashboard;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class NumberSquareView extends View {
    private Paint paint;
    private int number;

    public NumberSquareView(Context context, int number) {
        super(context);
        this.number = number;
        initPaint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setColor(Color.BLACK); // 设置画笔颜色
        paint.setTextSize(50f); // 设置文字大小
        paint.setTextAlign(Paint.Align.CENTER); // 设置文字居中对齐
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 获取View的中心点
        int width = getWidth();
        int height = getHeight();
        int sideLength = Math.min(width, height);
        float centerX = width / 2f;
        float centerY = height / 2f;

        // 绘制正方形
        canvas.drawRect(centerX - sideLength / 2, centerY - sideLength / 2,
                centerX + sideLength / 2, centerY + sideLength / 2, paint);

        // 在正方形中心绘制数字
        canvas.drawText(String.valueOf(number), centerX, centerY, paint);
    }
}